<?php
class corner_case {

	var $CI;
	var $corner_case_model;

	public function __construct() {
		$this->CI =& get_instance();
		$this->CI->load->model("sys/sys_corner_case_model");
		$this->corner_case_model =$this->CI->sys_corner_case_model;
	}

	public function get_corner_cases($parent_id) {
		return $this->corner_case_model->query_corner_cases($parent_id);
	}

	public function save_corner_case($corner_case){
		$check_result=$this->check_corner_case($corner_case);
		if (!$check_result['result']) {
			return $check_result;
		}
		$corner_case_id =$this->corner_case_model->insert_corner_case($corner_case);
		$result['result']=true;
		$result['redirect_url']=base_url()."index.php/sys_relate_manage/corner_case_list";
		return $result;
	}

	public function check_corner_case($corner_case,$corner_case_id=""){
		$result['result'] =true;
		$result['message']="制作工艺名称可以使用";
		if ($corner_case['corner_case_name']=="") {
			$result['result']=false;
			$result['message']="制作工艺名称不能为空";
			return $result;
		}
		$corner_case_info =$this->get_corner_case_info_by_name($corner_case['corner_case_name']);
		if ($corner_case_info=="") {
			$result['result']=true;
			$result['message']="制作工艺名称可以使用";
			return $result;
		}
		if ($corner_case_info['corner_case_id']!=$corner_case_id) {
			$result['result']=false;
			$result['message']="制作工艺已经存在,请重新输入";
			return $result;
		}
		return $result;
	}


	public function query_corner_case_info($corner_case_id){
		return $this->corner_case_model->query_corner_case_info($corner_case_id);
	}

	public function get_corner_case_info_by_name($corner_case_name){
		return $this->corner_case_model->query_corner_case_info_by_name($corner_case_name);
	}

	public function set_delete_corner_case($corner_case_id){
		$this->corner_case_model->set_delete_corner_case($corner_case_id);

	}
	public function update_corner_case($corner_case,$corner_case_id){
		$check_result=$this->check_corner_case($corner_case,$corner_case_id);
		if (!$check_result['result']) {
			return $check_result;
		}
		$corner_case_id =$this->corner_case_model->update_corner_case($corner_case,$corner_case_id);
		$result['result']=true;
		$result['redirect_url']=base_url()."index.php/sys_relate_manage/corner_case_list";
		return $result;
	}

	public function query_corner_case_list(){
		$start		=	intval($this->CI->input->get("per_page"));
		$limit		=	$this->CI->config->item("page_size");
		return	$this->corner_case_model->query_corner_case_list($start,$limit);
	}
	public function query_corner_case_num(){
		return $this->corner_case_model->query_corner_case_num();
	}
	
	public function get_all_corner_case(){
		return $this->corner_case_model->get_all_corner_case();
	}
}
?>